package com.ruoyi.project.tool.swagger.UserController;

import com.ruoyi.framework.aspectj.lang.annotation.SignatureValidation;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.system.domain.*;
import com.ruoyi.project.system.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 整屋装修Controller
 *
 * @author jjp
 * @date 2020-04-26
 */
@RestController
@Api("整屋装修")
@RequestMapping("/mobileUser/decoration")
public class UserHouseDecorationController extends BaseController {
    @Autowired
    private ISysHouseDecorationService sysHouseDecorationService;
    @Autowired
    private ISysMobileUserService sysMobileUserService;
    @Autowired
    private ISysHouseDecorationMomentService sysHouseDecorationMomentService;
    @Autowired
    private ISysMomentService sysMomentService;

    @Autowired
    private ISysUserService sysUserService;

    @Autowired
    private ISysMomentFileService sysMomentFileService;
    @Autowired
    private ISysDynamicPariseService sysDynamicPariseService;

    /**
     * 查询整屋装修列表
     */
    @ApiOperation("查询整屋装修列表")
    @SignatureValidation
    @PostMapping("/list")
    public AjaxResult list(@RequestBody SysHouseDecoration sysHouseDecoration) {
        List<SysHouseDecoration> list = sysHouseDecorationService.selectSysHouseDecorationList(sysHouseDecoration);
        for (int i = 0; i < list.size(); i++) {
            Long decorationId = list.get(i).getDecorationId();
            List<SysHouseDecorationMoment> houseDecorationMomentList = sysHouseDecorationMomentService.selectSysHouseDecorationMomentByDecorationIdList(decorationId);
            List<SysMoment> sysMomentList = new ArrayList<>();
            for (int j = 0; j < houseDecorationMomentList.size(); j++) {
                Long momentId = houseDecorationMomentList.get(j).getMomentId();
                SysMoment sysMoment = sysMomentService.selectSysMomentById(momentId);
                List<SysMomentFile> sysMomentFiles = sysMomentFileService.selectSysMomentId(momentId);
                SysUser sysUser = sysUserService.selectUserGetUserName(sysMoment.getCreateBy());
                SysDynamicParise sysDynamicParise=new SysDynamicParise();
                sysDynamicParise.setDynamicId(decorationId);
                List<SysDynamicParise> pariseList = sysDynamicPariseService.selectSysDynamicPariseList(sysDynamicParise);
                sysMoment.setSysUser(sysUser);
                sysMoment.setSysMomentFile(sysMomentFiles);
                sysMoment.setPariseTotal(pariseList.size());
                sysMomentList.add(sysMoment);
            }
            list.get(i).setSysMomentList(sysMomentList);
        }
        return AjaxResult.success(list);
    }
}
